package com.maikang.exammall.api;

import com.maikang.exammall.entity.Category;
import com.maikang.exammall.entity.dto.FindAllRequest;
import com.maikang.exammall.entity.dto.ResponseDTO;
import com.maikang.exammall.service.CategoryService;
import lombok.extern.log4j.Log4j2;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import static com.maikang.exammall.entity.constant.ApiCacheKeyConstant.dictKey;

@RestController
@Log4j2
@RequestMapping("/api/categories")
public class CategoryController extends DictionaryController<Category, Long, CategoryService> {

    @PostMapping(value = "/search")
    @Override
    @Cacheable(value = dictKey, key = "'category:findAll:payload:'+#findAllRequest.hashCode()")
    public ResponseDTO<Iterable<Category>> findAll(@RequestBody(required = false) FindAllRequest<Category> findAllRequest) {
        return ResponseDTO.ok(service.findAll());
    }
}
